/*
 * @Descripttion:调用后端商品接口的函数
 * @Author: congz
 * @Date: 2020-06-10 18:59:36
 * @LastEditors: congz
 * @LastEditTime: 2020-08-12 20:57:07
 */
import request from '@/api/utils/request'

import axios from 'axios'

// 创建商品
// const postProduct = form =>
//   axios.post('/api/v1/products', form).then(res => res.data)
export function postProduct(form) {
  let target = '/postProduct/'
  return request.post(target, form)
}

// 读商品详情
export function showProduct(id) {
  let target = '/showProduct?id=' + id
  return request.get(target)
}

// const showProduct = id =>
//   axios.get(`/api/v1/products/${id}`).then(res => res.data)

// 读取商品列表
export function listProducts(category_first_ID,category_second_ID, start, limit) {
  // 创建字典映射

  let target = '/listProducts?category_first_id=' + category_first_ID +'&category_second_id='+category_second_ID
    + '&start=' + start + '&limit=' + limit
  return request.get(target)
}

export function SortProducts(category_first_ID, start, limit) {
  // 创建字典映射

  let target = '/SortProducts?category_first_id=' + category_first_ID + '&start=' + start + '&limit=' + limit
  return request.get(target)
}

export function GetAllProducts (start, limit) {
  // 创建字典映射
  let target = '/AllProducts?&start=' + start + '&limit=' + limit
  return request.get(target)
}
// const listProducts = (category_id, start, limit) =>
//   axios
//     .get('/api/v1/products', { params: { category_id, start, limit } })
//     .then(res => res.data)

//读取商品的图片
export function showPictures(id) {
  let target = '/showPictures?id=' + id
  return request.get(target)
}
// const showPictures = id => axios.get(`/api/v1/imgs/${id}`).then(res => res.data)

//搜索商品
export function searchGoods(form) {
  let target = '/searchGoods/'
  return request.post(target, form)
}

// const searchProducts = form =>
//   axios.post('/api/v1/searches', form).then(res => res.data)

// 排行榜详情
export function showRanking() {
  let target = '/showRanking/'
  return request.get(target)
}
// const showRanking = () => axios.get('/api/v1/ranking/').then(res => res.data)

